import Category from "@/model/CateEnum";

class ItemDetail {
  // !表示非空
  id!: number;
  // 直接将枚举值给了形参
  categoryId!: Category;
  title!: string;
  content!: string;
  createTime!: string;

  constructor(
    id: number = -1,
    categoryId: Category = -1,
    title: string = "",
    content: string = ""
  ) {
    this.id = id;
    // 使用枚举类型代表文章分类
    this.categoryId = categoryId;
    this.title = title;
    this.content = content;
    this.createTime = this.toSelfDateStr(Date.now());
  }

  // 将时间毫秒转换成年月日时分秒的日期
  toSelfDateStr(timeStr: number): string {
    let date = new Date(timeStr);
    let dateStr =
      date.getFullYear() +
      "-" +
      (date.getMonth() + 1) +
      "-" +
      date.getDate() +
      " " +
      date.getHours() +
      ":" +
      date.getMinutes() +
      ":" +
      date.getSeconds();
    return dateStr;
  }
}

export default ItemDetail
